]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
grabHelper: Add (promised-based) grabAsync()
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 19 Dec 2019 02:28:50 +0000 (03:28 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 20 Dec 2019 14:41:32 +0000 (15:41 +0100)
Some GrabHelper uses are in the form:

    doPreGrabStuff();

    this._grabHelper.grab({
        onUngrab: () => {
            undoPreGrabStuff();
        },
    });

A promise-based variant allows to write this more cleanly as:

    doPreGrabStuff();

    await this._grabHelper.grabAsync();

    undoPreGrabStuff();

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/903

js/ui/grabHelper.js

index ffe07b2ec97de7e5ce56f1148aee131dca9480f7..2ba2aad9a3295d987ccaa3b3132e189f517b1b13 100644 (file)
@@ -194,6 +194,15 @@ var GrabHelper = class GrabHelper {
         return true;
     }
 
+    grabAsync(params) {
+        return new Promise((resolve, reject) => {
+            params.onUngrab = resolve;
+
+            if (!this.grab(params))
+                reject(new Error('Grab failed'));
+        });
+    }
+
     _takeModalGrab() {
         let firstGrab = this._modalCount == 0;
         if (firstGrab) {